package com.bst.web.base;

import java.util.*;

import com.bst.base.vo.BaseNoteParamVO;
import com.bst.common.utils.DateUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.bst.common.annotation.Log;
import com.bst.common.enums.BusinessType;
import com.bst.base.domain.BaseNote;
import com.bst.base.service.IBaseNoteService;
import com.bst.common.core.controller.BaseController;
import com.bst.common.core.domain.AjaxResult;
import com.bst.common.utils.poi.ExcelUtil;
import com.bst.common.core.page.TableDataInfo;

/**
 * 系统通知Controller
 * 
 * @author ruoyi
 * @date 2023-11-15
 */
@Controller
@RequestMapping("/base/note")
public class BaseNoteController extends BaseController
{
    private String prefix = "system/base/note";

    @Autowired
    private IBaseNoteService baseNoteService;

    @GetMapping()
    public String note(String source, ModelMap mmap)
    {
        mmap.put("source",source);
        //默认查询最近一周
        Date begin = DateUtil.calculate(new Date(), Calendar.DAY_OF_MONTH,-6);
        Date end = DateUtil.calculate(new Date(), Calendar.DAY_OF_MONTH,1);
        mmap.put("dayBegin",DateUtil.FORMAT_YYYY_MM_DD.format(begin));
        mmap.put("dayEnd", DateUtil.FORMAT_YYYY_MM_DD.format(end));
        return prefix + "/note";
    }

    /**
     * 查询系统通知列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BaseNoteParamVO baseNote)
    {
        startPage();
        List<BaseNote> list = baseNoteService.selectBaseNoteList(baseNote);
        return getDataTable(list);
    }

    /**
     * 新增系统通知
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存系统通知
     */
    @Log(title = "系统通知", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BaseNote baseNote)
    {
        return toAjax(baseNoteService.insertBaseNote(baseNote));
    }

    /**
     * 修改系统通知
     */
    @GetMapping("/edit/{idNote}")
    public String edit(@PathVariable("idNote") Long idNote, ModelMap mmap)
    {
        BaseNote baseNote = baseNoteService.selectBaseNoteByIdNote(idNote);
        mmap.put("baseNote", baseNote);
        return prefix + "/edit";
    }

    /**
     * 修改保存系统通知
     */
    @Log(title = "系统通知", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BaseNote baseNote)
    {
        return toAjax(baseNoteService.updateBaseNote(baseNote));
    }

    @GetMapping( "/cancel")
    @Log(title = "作废冻结患者未发送信息", businessType = BusinessType.UPDATE)
    @ResponseBody
    public AjaxResult updateCancelForInvalidPati(){
        int i = baseNoteService.updateCancelForInvalidPati();
        return AjaxResult.success(i);
    }
    /**
     * 删除系统通知
     */
    @Log(title = "系统通知", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        List<Long> longIds = new ArrayList<>();
        for(String id:ids.split(",")) {
            longIds.add(Long.parseLong(id));
        }
        baseNoteService.updateStatusByIds(2, longIds);
        return AjaxResult.success();
    }
}
